const api = 'http://api.zymk.cn/app_api/v3/'

function goback() {
	history.go(-1)
}

function getHelpContent(target, help_id) {
	let isDone = target.children('.content').attr('data-done');
	if(isDone == 'false'){
		target.children('.content').html("<p style='margin: 0 auto'>loading...</p>");
		$.ajax({
			url: api + 'gethelpcontent/?help_id=' + help_id,
			dataType: 'jsonp',
			success: function (res) {
				let tmpData = res.data.help_content;
				// 过滤html标签和空行
				tmpData = tmpData.replace(/<\/?[^>]*>/g, '').split(/[\r\n]{1,3}/g);
				// 筛选去除无效内容
				tmpData = tmpData.filter(item => { return item });

				if(isDone == 'false'){
					let str = '';
					tmpData.forEach(item => {
						str += '<p>' + item + '</p>';
					})
					target.children('.content').html(str);
					target.children('.content').attr('data-done', 'true');
				}
			}
		})		
	}
}

$(function () {
	$('.back').on('click', function () {
		goback()
	})
	$('.menus').on('click', function (e) {
		let help_id = e.target.dataset.id;
		getHelpContent($(this), help_id);
		$(this).children('.content').removeClass('hide')
		$(this).siblings('.menus').children('.content').addClass('hide')
	})
})